package com.chainyoung.component_tmperson.ui.view;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.chainyoung.component_tmperson.entity.WalletPercent;

import java.util.List;

public class WalletPercentView extends LinearLayout {


    public WalletPercentView(Context context) {
        super(context);
    }

    public WalletPercentView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public WalletPercentView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setViews(List<WalletPercent> data) {
        this.setOrientation(HORIZONTAL);
        int totalWidth = this.getWidth();
        this.removeAllViews();
        if (data.isEmpty()) {
            return;
        }
        for (WalletPercent item : data) {
            View view = new View(getContext());
            int width = (int) (totalWidth * item.getPercent());
            view.setLayoutParams(new LinearLayoutCompat.LayoutParams(width, ViewGroup.LayoutParams.MATCH_PARENT));
            view.setBackgroundColor(Color.parseColor(item.getColor()));
            this.addView(view);
        }
    }


}
